import _ from "lodash";

function get(data) {
  return new Promise((resolve, reject) => {
    setTimeout(function() {
      if (data) {
        resolve({ data: data, success: true });
      } else {
        reject("error");
      }
    }, 300);
  });
}

function query(data, key, value) {
  return new Promise((resolve, reject) => {
    setTimeout(function() {
      if (data) {
        let result = [];
        _.each(data, (item) => {
          if (_.eq(item[key], value)) {
            result.push(item);
          }
        });
        resolve({ data: result, success: true });
      } else {
        reject("error");
      }
    }, 300);
  });
}

export { get, query };
